package cn.agiledata.bank.common.servlet;

import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;

import cn.agiledata.bank.account.util.TransactionInterceptor;

public class OpenHibernateSessionInViewFilter extends OpenSessionInViewFilter {


	protected Session getSession(SessionFactory sessionFactory)
			throws DataAccessResourceFailureException {
		Session session = SessionFactoryUtils.getNewSession(sessionFactory,
				new TransactionInterceptor());
		session.setFlushMode(FlushMode.NEVER);
		return session;
	}
	protected void closeSession(Session session, SessionFactory factory) {
		session.flush();
		super.closeSession(session, factory);
	}

}
